﻿///////////////////////////////////////////////////////////////////////////////
//
// Copyright (C) 2008-2009 David Hill. All rights reserved.
//
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
// KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
// PARTICULAR PURPOSE.
///////////////////////////////////////////////////////////////////////////////
using System;
using System.ComponentModel;
using Microsoft.Practices.Composite.Presentation.Commands;
using Microsoft.Practices.Composite.Events;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Composite.Regions;
using AuthenticationService.Client;
using Microsoft.Practices.Composite.UnityExtensions;
using Microsoft.Practices.Composite.Modularity;
using System.Collections.Generic;
using System.Collections.ObjectModel;

namespace MyModules.Module.ViewModels
{
    /// <summary>
    /// ViewModel for View1.
    /// </summary>
    public class MyModulesViewModel : INotifyPropertyChanged
    {
        WebContext _context;
        private readonly IEventAggregator _eventAggregator;
        private SubscriptionToken _subscriptionToken;
        private readonly IRegionManager _regionManager;
        private readonly IUnityContainer _container;
        private ObservableCollection<ModuleInfo> _modulesList;

        public ObservableCollection<ModuleInfo> ModulesList
        {
            get { return _modulesList; }
            set 
            { 
                _modulesList = value;
                NotifyPropertyChanged("ModulesList");
            }
        }

        public string HeaderInfo
        {
            get
            {
                return "My Modules";
            }
        }

        public MyModulesViewModel(IUnityContainer container, IEventAggregator eventAggregator, IRegionManager regionManager, WebContext context)
        {
            _container = container;
            _eventAggregator = eventAggregator;
            _regionManager = regionManager;
            _context = context;

            ModuleCatalog catalog = (ModuleCatalog)_container.Resolve<IModuleCatalog>();
            _modulesList = new ObservableCollection<ModuleInfo>();
            foreach (ModuleInfo mi in catalog.Modules)
            {
                _modulesList.Add(mi);
            }

            // Initialize this ViewModel's commands.
            Command1 = new DelegateCommand<string>(ExecuteCommand1, CanExecuteCommand1);
        }

        #region Command1
        public DelegateCommand<string> Command1 { get; private set; }

        private void ExecuteCommand1(string commandParameter)
        {
        }

        private bool CanExecuteCommand1(string commandParameter)
        {
            return true;
        }

        #endregion

        #region INotifyPropertyChanged Members
        public event PropertyChangedEventHandler PropertyChanged;

        private void NotifyPropertyChanged(string propertyName)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
            }
        }
        #endregion
    }
}
